
#include <iostream>
#include <cstring>
using namespace std;

const int N = 5010 , INF = 0x3f3f3f3f;
int g[N][N] , dis[N];

int n , m;
int Prim()
{
    memset(dis,0x3f,sizeof dis)
    int res = 0;
    for(int i = 0 ; i < n ; ++i)
    {
        int t = -1;
        for(int j = 1 ; j <= n ; ++j)
            if(!st[j] && (t == -1 || dis[t] > dis[j])) t = j;
        if(i && t == INF) return INF;
        if(i) res += dis[i];
        for(int j = 1 ; j <= n ; ++j) dis[j] = min(dis[j],g[t][j]);
        st[t] = true;
    }   
    return res;
}
int main()
{
    cin >> n >> m;
    memset(g,0x3f,sizeof g);
    for(int i = 0 ; i < m ; ++i)
    {
        int a , b , c;
        cin >> a >> b >> c;
        g[a][b] = g[b][a] = min(g[a][b] , c);
    }
    int t = Prim();
    if(t > INF / 2) printf("orz");
    else printf("%d",t);
    return 0;
}